import React, { useEffect, useState } from 'react'
import PubSub from 'pubsub-js'
import Item from './Item'
export default function List() {
    const [searchList, setSearchList] = useState({ isInit: true, isSearch: false, data: [] })
    useEffect(() => {
        PubSub.subscribe('github', (_, data) => {
            setSearchList(data)
        })
    }, [])
    return (
        <div className="row">
            {
                searchList.isInit ? <h2>请输入搜索内容</h2> :
                    searchList.isSearch ? <h2>正在搜索中。。。</h2> :
                        searchList.data.map(item => {
                            return <Item key={item.id}{...item} />
                        })
            }
        </div>
    )
}
